package com.wangyadong.hobby.common.exception;

import com.wangyadong.hobby.common.utils.HobbyResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author : wangyadong
 * @Date : create in 2018/6/4  16:32
 * @Description : 全局异常处理器
 */
@ControllerAdvice
public class ExceptionController {
    private Logger logger = LoggerFactory.getLogger(ExceptionController.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public HobbyResult handlerException(Exception e) {
        logger.error("发送错误", e);
        return HobbyResult.fail(e.getMessage());
    }
}
